const fs=require('fs');
const path=require('path');
const http=require('http');
const argv=process.argv;

http.createServer((req,res)=>{
    if(argv[2]){
        var filePath=path.join(__dirname,'/'+argv[2]);
        fs.access(filePath,(err)=>{
            if(err){
                console.log(err);
            }else{
                fs.readFile(filePath,(err,data)=>{
                    if(err){
                        console.log(err);
                        res.end();
                    }else{
                        res.writeHead(200,{'content-type':'text/html;charset=utf-8'});
                        res.end(data.toString('utf-8'));
                    }
                })
            }
        })
    }
}).listen(8081);